import { _decorator, Camera, Component, director, Node, UITransform, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('UITools')
export class UITools {
    /**
     * 世界坐标转屏幕坐标 ，根据目标节点在ui上的位置来转换
     * @param node 需要转换的节点
     * @param targetNode 目标节点
     * @returns screenPos 屏幕坐标
     * */
    public static worlToScreen(node: Node, targetNode: Node): Vec3 {
        let worldPos = node.getWorldPosition();
        let targetNodeTransform = targetNode.getComponent(UITransform);
        let screenPos = targetNodeTransform.convertToNodeSpaceAR(worldPos);
        return screenPos;
    }
}


